import player_Control from "../rabbit/player_Control"
import ontrigger from "./ontrigger";
export default class Wolve extends Laya.Script {

    constructor() { 
        super();
        Wolve._intance = this
     }
    private wolve_ani_1: Laya.Animation        //狼动画
    private box_collider_1:Laya.BoxCollider    //狼盒子碰撞器
    private rigid_body_1:Laya.RigidBody        //狼刚体组件

    public isgameover:boolean
    public static _intance:Wolve

    onEnable(): void {
        //初始化狼
        this.initWolve()
        //狼添加碰撞体
        this.rigidWolve()
        //初始化狼移动动画
        this.enterAni()
        //是否游戏结束
        this.isgameover=true
    }

    /**在场景中添加狼动画 */
    initWolve() {
        this.wolve_ani_1 = new Laya.Animation()
        this.wolve_ani_1.loadAtlas("F:/MyLaya/Rabbit_Gohome/laya/assets/ani/wolve_Left.atlas", null, 'left')//左移动
        this.wolve_ani_1.loadAtlas("F:/MyLaya/Rabbit_Gohome/laya/assets/ani/wolve_Right.atlas", null, 'right')//右移动
        //将狼添加到舞台
        this.owner.addChild(this.wolve_ani_1)
        this.wolve_ani_1.pos(950, 318)
        this.wolve_ani_1.interval = 300
        this.wolve_ani_1.scale(1.2, 1.2)
        this.wolve_ani_1.play(0, true, 'left')
        this.wolve_ani_1.addComponent(ontrigger)
    }
    /**狼添加刚体 */
    rigidWolve(){
        //狼添加Boxcollider组件
        this.box_collider_1=this.wolve_ani_1.addComponent(Laya.BoxCollider)
        this.box_collider_1.width = 80
        this.box_collider_1.height = 35
        this.box_collider_1.y=15
        this.box_collider_1.label = "wolvel"
        //狼添加RigidBody组件
        this.rigid_body_1=this.wolve_ani_1.addComponent(Laya.RigidBody)
        //狼设置重力系数
        this.rigid_body_1.gravityScale=10
        this.rigid_body_1.allowRotation = false
    }

    enterAni() {
        Laya.Tween.to(
            this.wolve_ani_1,
            { x: 200 },
            6000,
            null,
            Laya.Handler.create(this, () => {
                this.wolve_ani_1.play(0, true, 'right')
                Laya.Tween.to(
                    this.wolve_ani_1,
                    { x: 950 },
                    6000,
                    null
                )
            })
        )
        Laya.timer.loop(12000, this, () => {
            this.wolve_ani_1.play(0, true, 'left')
            Laya.Tween.to(
                this.wolve_ani_1,
                { x: 200 },
                6000,
                null,
                Laya.Handler.create(this, () => {
                    this.wolve_ani_1.play(0, true, 'right')
                    Laya.Tween.to(
                        this.wolve_ani_1,
                        { x: 950 },
                        6000,
                        null
                    )
                })
            )
        })
    } 




    onDisable(): void {
    }
}